#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System;

namespace Grawlix.Services
{
	/// <summary>
	/// An <see cref="IEnvironmentFactory"/> that spawns
	/// <see cref="AppDomainEnvironment"/> objects.
	/// </summary>
	public class AppDomainEnvironmentFactory :
		IEnvironmentFactory
	{
		/// <summary>
		/// Directories specifying where to search for assemblies.
		/// </summary>
		private readonly string _searchPaths;

		/// <summary>
		/// Initializes a new instance of the 
		/// <see cref="AppDomainEnvironmentFactory"/> class.
		/// </summary>
		/// <param name="searchPaths">Directories specifying where to
		/// search for assemblies.</param>
		public AppDomainEnvironmentFactory(string searchPaths)
		{
			_searchPaths = searchPaths;
		}

		/// <summary>
		/// Directories specifying where to search for assemblies.
		/// </summary>
		public string SearchPaths
		{
			get { return _searchPaths; }
		}

		/// <summary>
		/// Creates a new <see cref="IExecutionEnvironment"/>.
		/// </summary>
		/// <param name="name">The name of the environment to create.
		/// </param>
		/// <returns>The new environment.</returns>
		public IExecutionEnvironment Create(string name)
		{
			return new AppDomainEnvironment(name,
			                                AppDomain.CurrentDomain.
			                                	BaseDirectory,
			                                SearchPaths);
		}
	}
}